#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import time
import threading


def run(num, lk):
    lk.acquire()  # 获取锁
    print("线程运行中 {}".format(threading.current_thread().getName()))
    time.sleep(1)
    lk.release()  # 释放锁


samapahore = threading.BoundedSemaphore(5)
if __name__ == '__main__':
    for i in range(10):   # 一次执行5个， 其它的等线程完成在继续执行
        t = threading.Thread(target=run, args=(i, samapahore))
        t.start()
